<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			
		</script>
	</head>
	<body>
		<table>
			  <tr>
				 <td><img src="" /></td>
				 <td colSpan="3">购物简易计算器</td>
			  </tr>
			  <tr>
				 <td>第一个数</td>
				 <td colSpan="3">
					 <input type="text" id="num1" />
				 </td>
			  </tr>
			  <tr>
				 <td>第二个数</td>
				 <td colSpan="3">
					 <input type="text" id="num2" />
				 </td>
			  </tr>
			  <tr>
				 <td>
					 <input type="button" value=" + " onclick='cal("+")'/>
					<!-- <input type="button" value=" + " onclick="add()"/> -->
				 </td>
				 <td>
					 <input type="button" value=" - " onclick="cal('-')"/>
					<!-- <input type="button" value=" - " onclick="sub()"/> -->
				 </td>
				 <td>
					 <input type="button" value=" * " onclick="mul()"/>
				 </td>
				 <td>
					 <input type="button" value=" / " onclick="div()"/>
				 </td>
			  </tr>
			  <tr>
				 <td>计算结果</td>
				 <td colSpan="3">
					 <input type="text" id="result" />
				 </td>
			  </tr>
		  </table>
		  
		  <script type="text/javascript">
			  function cal(type) {
				   var inputValue1 = document.getElementById('num1').value;
				   var inputValue2 = document.getElementById('num2').value;
				   var resultValue;
				   switch (type){
				   	case '+':
						resultValue = parseInt(inputValue1) + parseInt(inputValue2);
				   		break;
					case '-':
						resultValue = parseInt(inputValue1) - parseInt(inputValue2);
						break;
				   	default:
				   		break;
				   }
				   var resultInput = document.getElementById('result');
				   resultInput.value = resultValue;
			  }
			  
			  
		  	   function add() {
				   //var input1 = document.getElementById('num1');
				   //var inputValue1 = input1.value;
				   var inputValue1 = document.getElementById('num1').value;
				   var inputValue2 = document.getElementById('num2').value;
				   var resultValue = parseInt(inputValue1) + parseInt(inputValue2);
				   var resultInput = document.getElementById('result');
				   resultInput.value = resultValue;
			   }
			   
			   function sub() {
				   var inputValue1 = document.getElementById('num1').value;
				   var inputValue2 = document.getElementById('num2').value;
				   var resultValue = parseInt(inputValue1) - parseInt(inputValue2);
				   var resultInput = document.getElementById('result');
				   resultInput.value = resultValue;
			   }
		  </script>
	</body>
</html>
